package com.shanyin.framework.common.base;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;

import com.shanyin.framework.common.util.StringUtil;

/***
 ** @category 请用一句话来描述其用途...
 ** @author qing.yunhui
 ** @email: 280672161@qq.com
 ** @createTime: 2018年5月23日上午10:18:50
 **/
public class BaseServiceImpl<MODEL extends BaseModel<KEY>, KEY> implements BaseService<MODEL, KEY>{

	@Autowired
	private BaseDao<MODEL,KEY> baseDao;
	
	public int save(MODEL model) {
		if(null==model) throw new NullPointerException();
		return baseDao.insert(model);
	}

	public int saveBatch(List<MODEL> models) {
		if(null==models||models.size()==0) throw new NullPointerException();
		return baseDao.insertBatch(models);
	}

	public int update(MODEL model) {
		if(null==model) throw new NullPointerException();
		return baseDao.update(model);
	}

	public int deleteById(KEY id) {
		if(StringUtil.isEmptys(id)) {
			throw new NullPointerException();
		}
		return baseDao.delete(id);
	}

	public int deleteBatchByIds(List<KEY> ids) {
		if(StringUtil.isEmptys(ids)) {
			throw new NullPointerException();
		}
		return baseDao.deleteBatch(ids);
	}

	public MODEL getById(KEY id) {
		if(StringUtil.isEmptys(id)) {
			return null;
		}
		return baseDao.getById(id);
	}

	public int queryCount(Map<String, Object> map) {
		return baseDao.queryCount(map);
	}

	public List<MODEL> query(Map<String, Object> map) {
		return baseDao.query(map);
	}

}
